package ken.spring.cloud.alibaba.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;


/**
 * <ul>
 * <li>Title: DeptController</li>
 * <li>Description: TODO </li>
 * </ul>
 *
 * @author swc
 * @date 2022-06-27 16:11
 */
@RestController
public class DemoController {

    private static final Logger LOGGER = LoggerFactory.getLogger(DemoController.class);


    /***
     * 功能描述: 获取session
     * @param key
     * @param value
     * @param request
     * @return: java.lang.String
     * @author: swc
     * @date: 2022-08-08 15:49
    */
    @GetMapping("/getValue")
    public Object getValue(@RequestParam(name = "key", required = false) String key,
                           @RequestParam(name = "value", required = false) String value, HttpServletRequest request) {
        Object userInfo = request.getSession().getAttribute(key);
        return userInfo;
    }


    /***
     * 功能描述: 设置session
     * @param key
     * @param value
     * @param request
     * @return: java.lang.String
     * @author: swc
     * @date: 2022-08-08 15:49
     */
    @GetMapping("/setValue")
    public String setValue(@RequestParam(name = "key", required = false) String key,
                           @RequestParam(name = "value", required = false) String value, HttpServletRequest request) {
        if (!ObjectUtils.isEmpty(key) && !ObjectUtils.isEmpty(value)) {
            request.getSession().setAttribute(key, value);
        }
        return "home";
    }



}
